// 抽奖模块
// 获取相关节点
let rotate_img = document.querySelector(".img_1");
let click_img = document.querySelector(".img_2");
let num = 0;// 定义一个随机数
let part = 60; // 每一部分的度数

// 附加点击效果
click_img.addEventListener("click",function(){
	RotateImg(rotate_img);
})

// 定义旋转函数
// 思路，随机数得出一个旋转数值，然后判断在哪个区间，显示相关奖品提示
function RotateImg(r){
	timer = setTimeout(function(){
		// 生成随机度数
		num = Math.floor(Math.random()*3600);
		// 做判断旋转不能小于一圈
		if(num<360){
			num = Math.floor(Math.random()*3600);
		}
		// 拼接度数实现旋转
		rotate_img.style.transform = "rotate("+ num +"deg)";
		console.log("没取余的：",num);
		rdm = num%360;
		if(rdm<=part*1){
			console.log(rdm);
			console.log("中了0.1BTC");
		}
		else if(rdm<=part*2){
			console.log(rdm);
			console.log("中了ipad");
		}
		else if(rdm<=part*3){
			console.log(rdm);
			console.log("中了888TD");
		}
		else if(rdm<=part*4){
			console.log(rdm);
			console.log("中了666TD");
		}
		else if(rdm<=part*5){
			console.log(rdm);
			console.log("中了111TD");
		}
		else if(rdm<=part*6){
			console.log(rdm);
			console.log("中了iPhoneXR");
		}
		
		
	},200);
	
	
}
// 排行榜模块
var info = [
	{time:"2018.7.23 18:30",result:"0.1BTC"},
	{time:"2018.7.23 18:30",result:"0.1BTC"},
	{time:"2018.7.23 18:30",result:"0.1BTC"},
	{time:"2018.7.23 18:30",result:"0.1BTC"},
	{time:"2018.7.23 18:30",result:"0.1BTC"},
	{time:"2018.7.23 18:30",result:"0.1BTC"},
	{time:"2018.7.23 18:30",result:"0.1BTC"},
	{time:"2018.7.23 18:30",result:"0.1BTC"},
	{time:"2018.7.23 18:30",result:"0.1BTC"},
	{time:"2018.7.23 18:30",result:"0.1BTC"},
	{time:"2018.7.23 18:30",result:"0.1BTC"},
];
let n_data = document.querySelector(".n_data");
info.forEach(function(ele,index){
	let item = document.createElement("div");
	item.classList.add("item");
	item.innerHTML = `<span>${ele.time}</span><span>${ele.result}</span>`
	n_data.appendChild(item);
})
let index = 0;
function move(){
	index++;
	n_data.style.transitionDuration = "1s";
	n_data.style.transform = `translate3d(0,-${index*41}px,0)`;
}
setInterval(function(){
	move();
},2000)
n_data.addEventListener("transitionend",function(){
	// 动画结束之后，我们可以偷偷后撤一步
	// if(index>=info.length){
		index--;
		n_data.style.transitionDuration = "0s";
		n_data.style.transform = `translate3d(0,-${index*40}px,0)`;
	// }
	// 真正做的移动，就是不断把第一个节点，挪到最后一个位置
	let firstChild = n_data.firstElementChild;
	n_data.appendChild(firstChild);
})
